<template>
  <div class="transaction-surveillance container pb">
    <p class="bread">
      <a href="#/index/lms-order-list">法律服务监控员-订单管理</a> >
      <a href="javascript:void(0);" class="font-s-18">法律服务通知单</a>
    </p>
    <div class="bg-c-fff box-border">
      <h3 class="tm-title">法律服务</h3>
      <step :stepData="stepData" :stepNum="stepNum" @stepRouter="stepRouter"></step>
    </div>
    <div class="surveillance-title-box">
      <div class="surveillance-title">法律服务监控流程图</div>
      <div class="btn-box">
        <button type="button" class="white-button" @click="onEnding" v-show="state===3">终止交易</button>
        <button type="button" class="white-button" @click="onMessage" v-show="state===3">发送消息</button>
        <button type="button" class="white-button" @click="clockShowClick" v-show="state===3">设置提醒闹钟</button>
      </div>
    </div>
    <div class="progress-box">
      <company-name-container :companyNames="companyNames"></company-name-container>
      <div class="line" :class="{center: companyNames.length===2}" :style="{height: (events.length+0.5)*90+60+'px'}" v-show="events.length">
        <div class="arrow"></div>
      </div>
      <event-item v-for="(item,index) in events" :key="index" :pstate="item.state" :totalSides="companyNames.length" :side="item.side" :content="item.content" :files="item.files" :eventId="item.id" :isAudit="true" :serviceId="id" :tradeType="'law'" :isProgressing="state===3"></event-item>
      <div class="submit-box" :class="{'tc': companyNames.length===2}">
      </div>
      <p class="tc">交易监控结束</p>
    </div>
    <vodal :show="endingShow" animation="zoom" :width="380" :height="310" @hide="endingShow = false">
      <div class="vodal-xxbox">
        <h2>添加监控事件</h2>
        <form @submit.prevent="onEndingClick">
          <div class="con">
            当前交易监控有未审核或待上传的文件，确认提前终止吗？
          </div>
          <div class="tc auto vodal-box">
            <button type="submit" class="blue-button">确认</button>
            <button type="button" class="white-button" @click="endingShow = false">取消</button>
          </div>
        </form>
      </div>
    </vodal>
    <vodal :show="msgShow" animation="zoom" :width="380" :height="330" @hide="msgShow = false">
      <div class="vodal-msgbox">
        <h2>发送消息</h2>
        <form @submit.prevent="onMsgClick">
          <ul class="con">
            <li>
              <span>消息内容：</span>
              <textarea class="vt" v-model="msgText"></textarea>
            </li>
            <li>
              <span>多方监控：</span>
              <input type="checkbox" id="a" value="1" v-model="cust">
              <label for="a">甲方客户</label>
              <input type="checkbox" id="b" value="2" v-model="lawyer">
              <label for="b">乙方律师</label>
            </li>
            <li class="tc auto vodal-box">
              <button type="submit" class="blue-button">确认</button>
              <button type="button" class="white-button" @click="cancelMsg">取消</button>
            </li>
          </ul>
        </form>
      </div>
    </vodal>
    <vodal :show="clockShow" animation="zoom" :width="420" :height="480" @hide="clockShow=false">
      <form @submit.prevent="onClockSubmit">
        <div class="vodal-main clock">
          <h4>设置提醒闹钟</h4>
          <ul>
            <li>
              <h5>闹钟时间：</h5>
              <div class="box">
                <calendar value="" format="yyyy-MM-dd" width="95px" placeholder="年-月-日" ref="time"></calendar>
                <select v-model="hour" class="time vt">
                  <option value="">--</option>
                  <option v-for="n in 24">{{n | numFilter}}</option>
                </select>时：
                <select v-model="minute" class="time vt">
                  <option value="">--</option>
                  <option v-for="n in 60">{{n | numFilter}}</option>
                </select>分
              </div>
            </li>
            <li>
              <h5>提醒内容：</h5>
              <div class="box">
                <p> <span>提醒事件：</span>
                  <select v-model="content">
                    <option value="">提醒事件</option>
                    <option :value="item.content" v-for="item in eventList">{{item.content}}</option>
                  </select>
                </p>
                <p><span>备注：</span>
                  <textarea class="vt" v-model="clockRemark"></textarea>
                </p>
              </div>
            </li>
            <li>
              <h5>多方提醒：</h5>
              <div class="box">
                <div class="dib">
                  <input type="checkbox" id="user" :value="userInfo" v-model="info">
                  <label for="user" class="vt">{{userName}}</label>
                </div>
                <div class="dib">
                  <input type="checkbox" id="customer" :value="customerInfo" v-model="info">
                  <label for="customer" class="vt">{{customerName}}</label>
                </div>
                <div class="dib">
                  <input type="checkbox" id="lawyer" :value="lawyerInfo" v-model="info">
                  <label for="lawyer" class="vt">{{lawyerName}}</label>
                </div>
              </div>
            </li>
          </ul>
          <div class="auto tc">
            <button type="submit" class="blue-button xl-btn-css">确认</button>
            <button type="button" class="blue-button xl-btn-css" @click="clockShow=false">取消</button>
          </div>
        </div>
      </form>
    </vodal>
  </div>
</template>
<script type="text/javascript">
import Step from '../components/Step'
import CompanyNameContainer from '../components/CompanyNameContainer'
import EventItem from '../components/EventItem'
import Calendar from '../components/Calendar'
export default {
  components: {
    Step,
    CompanyNameContainer,
    EventItem,
    Calendar
  },
  data() {
    return {
      id: '',
      stepNum: 2,
      stepData: [{
        name: '法律服务通知单'
      }, {
        name: '绘制流程图'
      }, {
        name: '法律服务监控'
      }, {
        name: '服务完成'
      }],
      companyNames: [],
      events: [],
      endingShow: false,
      msgShow: false,
      msgText: '',
      clockShow: false,
      state: 0,
      cust: false,
      lawyer: false,
      reciveType: '',
      hour: '',
      minute: '',
      eventList: [],
      info: [],
      clockRemark: '',
      content: '',
      customerName: '',
      customerInfo: '',
      lawyerName: '',
      lawyerInfo: '',
      relationIds: '',
      relationNames: ''
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this.getEvents()
  },
  methods: {
    getEvents() {
      this.$http.get('/legalService/read/detail', {
        params: {
          id: this.id
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.state = data.data.data.status
          this.customerName = '甲方客户' + data.data.data.customerName
          this.customerInfo = data.data.data.customerId + ',' + this.customerName
          this.lawyerName = '乙方律师' + data.data.data.lawyerName
          this.lawyerInfo = data.data.data.lawyerId + ',' + this.lawyerName
          this.companyNames = [{ name: this.customerName }, { name: this.lawyerName + '律师' }]
          this.eventList = data.data.data.eventList
          this.eventList.forEach(item => {
            let event = {}
            event.content = item.content
            event.side = item.memberOrder
            event.state = item.status
            event.files = item.fileList || []
            event.index = item.order
            event.id = item.id
            this.events.push(event)
          })
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onEnding() {
      this.endingShow = true
    },
    onEndingClick() {
      this.$http.post('/legalService/monitor/endService', {
        id: this.$route.query.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('终止交易已完成')
          this.$router.push('/index/lms-order-list')
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onMessage() {
      this.msgShow = true
    },
    onMsgClick() {
      if (!this.msgText) {
        this.$toasted.show('消息不能为空')
        return
      }
      if (this.cust === false && this.lawyer === false) {
        this.$toasted.show('请选择发送人')
        return
      }
      if (this.cust === true && this.lawyer === true) {
        this.reciveType = 3
      }
      if (this.cust === true && this.lawyer === false) {
        this.reciveType = 1
      }
      if (this.cust === false && this.lawyer === true) {
        this.reciveType = 2
      }
      this.$http.post('/message/send/legal/background', {
        orderId: this.$route.query.id,
        reciveType: this.reciveType,
        msgContent: this.msgText
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('消息已发送')
          this.msgShow = false
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    clockShowClick() {
      this.$refs.time.inputValue = ''
      this.hour = ''
      this.minute = ''
      this.content = ''
      this.clockRemark = ''
      this.info = []
      this.clockShow = true
    },
    onClockSubmit() {
      if (!this.$refs.time.inputValue) {
        this.$toasted.show('请选择年月日')
        return
      }
      if (!this.hour) {
        this.$toasted.show('请选择时')
        return
      }
      if (!this.minute) {
        this.$toasted.show('请选择分')
        return
      }
      if (!this.content) {
        this.$toasted.show('请选择提醒事件')
        return
      }
      if (!this.clockRemark) {
        this.$toasted.show('请填写备注')
        return
      }
      if (this.info.length === 0) {
        this.$toasted.show('请选择提醒方')
        return
      }
      this.relationIds = ''
      this.relationNames = ''
      this.info.forEach(i => {
        this.relationIds += i.split(',')[0] + ','
        this.relationNames += i.split(',')[1] + ','
      })
      this.$http.get('/sysClock/clock', {
        params: {
          time: this.$refs.time.inputValue + ' ' + this.hour + ':' + this.minute + ':00',
          relationId: this.$route.query.id,
          content: this.content,
          relationIds: this.relationIds.substring(0, this.relationIds.lastIndexOf(',')),
          relationNames: this.relationNames.substring(0, this.relationNames.lastIndexOf(',')),
          remark: this.clockRemark
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('提交成功')
          this.clockShow = false
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    stepRouter(i, name) {
      if (i === 0 && this.state >= 2) {
        this.$router.push('/lms-order-notice?id=' + this.$route.query.id)
      }
      if (i === 1 && this.state === 2) {
        this.$router.push('/lms-order-mapping?id=' + this.$route.query.id)
      }
      if (i === 1 && this.state > 2) {
        this.$toasted.show('请点击法律服务监控查看')
      }
      if (i === 2 && this.state >= 3) {
        this.$router.push('/lms-order-monitor?id=' + this.$route.query.id)
      }
      if (i === 3 && this.state >= 4) {
        this.$router.push('/lms-order-finish?id=' + this.$route.query.id)
      }
    },
    cancelMsg() {
      this.msgShow = false
      this.msgText = ''
      this.cust = false
      this.lawyer = false
    }
  },
  computed: {
    userInfo() {
      return this.$store.state.userInfo.id + ',法律服务监控员' + this.$store.state.userInfo.account
    },
    userName() {
      return '法律服务监控员' + this.$store.state.userInfo.account
    }
  },
  filters: {
    numFilter(v) {
      if (v > 0 && v < 11) {
        return 0 + (v - 1).toString()
      } else {
        return v - 1
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.tm-title {
  line-height: 40px;
  padding-left: 35px;
  font-size: 14px;
  color: #282828;
  border-bottom: 1px solid #ddd;
}

.pb {
  padding-bottom: 70px;
}

.surveillance-title-box {
  position: relative;
  width: 100%;
  height: 40px;
  line-height: 40px;
  margin-top: 20px;
  border-bottom: 1px solid #ddd;
  background-color: #fff;
  text-align: center;
}

.surveillance-title {
  font-size: 14px;
  color: #282828;
}

.surveillance-title-box .btn-box {
  position: absolute;
  top: 0;
  right: 100px;
  font-size: 14px;
}

.surveillance-title-box .white-button {
  width: 100px;
  height: 30px;
  line-height: 30px;
  margin-left: 10px;
}

.progress-box {
  position: relative;
  width: 100%;
  background-color: #fff;
  overflow-x: auto;
  padding-bottom: 20px;
}

.line {
  position: absolute;
  width: 2px;
  top: 0;
  left: 65px;
  margin-top: 10px;
  background-color: #cfcfcf;
}

.line.center {
  left: 50%;
}

.line .arrow {
  position: absolute;
  bottom: -10px;
  left: -7px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid #cfcfcf;
}

.submit-box {
  width: 100%;
  padding: 40px;
}

.submit-box button {
  width: 120px;
  height: 35px;
}

h2 {
  background-color: #d8e7ff;
  font-size: 14px;
  font-weight: bold;
  line-height: 40px;
  text-indent: 40px;
}

.con {
  margin: 30px 20px;
  padding: 13px 0 0 13px;
}

textarea {
  border: 1px solid #ddd;
  width: 240px;
  padding: 6px 10px;
  line-height: 20px;
  height: 120px;
}

.button .white-button,
.button .blue-button {
  width: 245px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  margin: 40px 15px;
}

.vodal-box button {
  margin: 0 15px;
  width: 120px;
  height: 35px;
}

.vodal-msgbox li:nth-of-type(2) {
  margin: 20px 0;
}

.clock h5 {
  padding-left: 30px;
  line-height: 35px;
  font-weight: bolder;
  margin-top: 10px;
}

.clock li .box {
  padding: 0px 45px;
}

.clock li .box p {
  margin-bottom: 15px;
}

.clock li .box select {
  border: 1px solid #ddd;
  height: 35px;
  width: 150px;
  color: #2f2f2f;
}

.clock li .box span {
  display: inline-block;
  width: 70px;
  text-align: right;
}

.clock li .box .time {
  width: 40px;
  height: 40px;
}

.clock li .box textarea {
  width: 250px;
  height: 80px;
}

.clock li .box .dib {
  margin-right: 15px;
  margin-bottom: 8px;
}

.clock button {
  margin: 20px 10px 0 10px;
}

</style>
